package dht;

import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

public final class Configuration {

    public static final int TCP_SERVER_PORT = 1234;
    public static final int UDP_PORT = 1233;
    public static final String DATABASE_FILE_NAME = "/opt/445C/database.raf";
    
    // moxie is at 129.3.20.3
    private static final String[] possibleHosts = new String[]{
        // g,           altair         lambda          wolf
        //"129.3.20.1", "129.3.20.2", "129.3.20.6", "129.3.20.36"
        "g", "altair", "lambda", // "wolf"
    };
    private static List<HostAddress> knownHosts;

    public static List<HostAddress> getAllHosts(HostAddress host) throws UnknownHostException {
        return getAllHosts(host.address().getHostName());
    }

    public static List<HostAddress> getAllHosts(String hostName) throws UnknownHostException {
        if (knownHosts == null)
            knownHosts = initializeHosts(possibleHosts);
        
        List<HostAddress> hosts = new ArrayList<HostAddress>();
        for (HostAddress host : knownHosts)
            if (!hostName.equalsIgnoreCase(host.address().getHostName())) hosts.add(host);
        return hosts;
    }

    private static List<HostAddress> initializeHosts(String[] addresses) throws UnknownHostException {
        List<HostAddress> hosts = new ArrayList<HostAddress>();
        for (String address : addresses)
            hosts.add(new HostAddress(address, UDP_PORT));
        return hosts;
    }
}
